﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KMS.Core.domain.model.project;
using KMS.Web.Views.Projects;
using KMS.Web.Tests.Factory;
using KMS.Core.domain.model.post;

namespace KMS.Web.Tests.views
{
    /// <summary>
    /// Summary description for ProjectViewModelTests
    /// </summary>
    [TestClass]
    public class ProjectViewModelTests
    {
        public ProjectViewModelTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ProjectViewModelCanBeConstructedWithResources()
        {
            var postFactory = new PostFactory();
            var resources = new List<Resource> { postFactory.CreateResourceWithTitle("test resource"), 
                postFactory.CreateResourceWithTitle("help"), 
                postFactory.CreateResourceWithTitle("tutorial") }; 

            var project = new Project("My project");
            var projectViewModel = new ProjectViewModel(project, resources);

            Assert.AreEqual("My project", projectViewModel.Name);
            Assert.AreEqual(3, projectViewModel.Resources.Count, "resources list shold contain 3 resources");
            Assert.AreEqual("test resource", projectViewModel.Resources[0].Title, "wrong resources[0] title");
            Assert.AreEqual("help", projectViewModel.Resources[1].Title, "wrong resources[1] title");
            Assert.AreEqual("tutorial", projectViewModel.Resources[2].Title, "wrong resources[2] title");
        }

        [TestMethod]
        public void ProjectViewModelCanBeConstructedWithoutResources()
        {
            var project = new Project("My project");
            var projectViewModel = new ProjectViewModel(project);

            Assert.AreEqual("My project", projectViewModel.Name); 
        }

        [TestMethod]
        public void ProjectViewModelCanBeConstructedWithoutParameters()
        {
            var projectViewModel = new ProjectViewModel();
            Assert.IsNull(projectViewModel.Resources);
            Assert.IsTrue(String.IsNullOrEmpty(projectViewModel.Name));
        }
    }
}
